package coms.ejb;

import Util.GenericReviewStrategy;
import Util.ReviewStrategy;
import Util.XMLUtil;
import coms.dataaccess.dao.ReviewDAO;
import coms.dataaccess.hibernate.HibernateDAOFactory;
import coms.dto.*;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;


@Stateless (mappedName="ReviewBean")
public class ReviewBean extends GenericBean<Review> implements ReviewBeanRemote{
    
  private ReviewDAO reviewDAO;
 
    @PostConstruct
    public void construct(){
        super.construct();
        HibernateDAOFactory factory = new HibernateDAOFactory();
        reviewDAO = factory.getReviewDAO();
    }  
    
    @Override
    public List<Review> getByPublication(Publication publication) {
          Review review = new Review();
          review.setPublication(publication);
          List<Review> reviewList = new ArrayList<Review>();
        try {
            reviewList = reviewDAO.search(review);
        } catch (SQLException ex) {
            Logger.getLogger(Review.class.getName()).log(Level.SEVERE, null, ex);
        }
         return reviewList;
    }
    
    @Override
    public List<Review> getByReviewer(User reviewer) {
          Review review = new Review();
          review.setReviewer(reviewer);
          List<Review> reviewList = new ArrayList<Review>();
        try {
            reviewList = reviewDAO.search(review);
        } catch (SQLException ex) {
            Logger.getLogger(Review.class.getName()).log(Level.SEVERE, null, ex);
        }
         return reviewList;
    }
}
